package com.deer.wms.base.system.service.bill.impl;

import com.deer.wms.base.system.dao.bill.BillOutDetailMapper;
import com.deer.wms.base.system.dao.bill.MaterialInfoMapper;
import com.deer.wms.base.system.model.bill.BillInMaster;
import com.deer.wms.base.system.model.bill.BillOutDetail;
import com.deer.wms.base.system.model.bill.MaterialInfo;
import com.deer.wms.base.system.model.bill.MaterialInfoCriteria;
import com.deer.wms.base.system.service.bill.IMaterialInfoService;
import com.deer.wms.common.core.service.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialInfoServiceImpl extends AbstractService<MaterialInfo, Integer> implements IMaterialInfoService {

    @Autowired
    MaterialInfoMapper materialInfoMapper;

    @Autowired
    BillOutDetailMapper billOutDetailMapper;

    @Override
    public List<MaterialInfo> selectMaterialList(MaterialInfoCriteria materialInfoCriteria) {
        return materialInfoMapper.selectMaterialList(materialInfoCriteria);
    }


    @Override
    public List<MaterialInfo> findList(MaterialInfoCriteria materialInfoCriteria) {
        return materialInfoMapper.findList(materialInfoCriteria);
    }


    @Override
    public List<MaterialInfo> findListForPullDown(MaterialInfoCriteria materialInfoCriteria) {
        return materialInfoMapper.findListForPullDown(materialInfoCriteria);
    }

    @Override
    public List<MaterialInfo> findByMaterialBatchId(String carrierId) {
        return materialInfoMapper.findByMaterialBatchId(carrierId);
    }

    @Override
    public int saveMaterialInfo(MaterialInfo materialInfo) {
        return materialInfoMapper.saveMaterialInfo(materialInfo);
    }

    @Override
    public int updateMaterialInfo(MaterialInfo materialInfo) {
        return materialInfoMapper.updateMaterialInfo(materialInfo);
    }

    @Override
    public MaterialInfo findMaterialInfo(MaterialInfo materialInfo) {

        return  materialInfoMapper.findMaterialInfo(materialInfo);
    }

    @Override
    public  List<MaterialInfo> findBillOut(String carrierId) {
        List<MaterialInfo> billOut = materialInfoMapper.findBillOut(carrierId);
        for (MaterialInfo info : billOut) {
            BillOutDetail byBillOutDetail = billOutDetailMapper.findByBillOutDetail(info.getMaterialId());
            if (null == byBillOutDetail){
                info.setState(6);// 过账失败
                continue;
            }
            info.setState(byBillOutDetail.getState());
        }
        return billOut;
    }


    @Override
    public List<MaterialInfo> findBillOutList(MaterialInfoCriteria materialInfo) {
        return materialInfoMapper.findBillOutList(materialInfo);
    }

    @Override
    public List<MaterialInfo> findBillOutParentMaterialIdList(String carrierId) {
        return materialInfoMapper.findBillOutParentMaterialIdList(carrierId);
    }

    @Override
    public int delectMaterialInfo(String carrierId) {
        return materialInfoMapper.delectMaterialInfo(carrierId);
    }

}
